package com.designpattern.singleton;

import com.designpattern.singleton.innerclasssingleton.InnerClassSingleton;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Test {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException, ClassNotFoundException {
//        Constructor<InnerClassSingleton> declaredConstructor = InnerClassSingleton.class.getDeclaredConstructor();
//        declaredConstructor.setAccessible(true);
//        InnerClassSingleton innerClassSingleton = declaredConstructor.newInstance();
//        InnerClassSingleton innerClassSingleton1 = InnerClassSingleton.getInstance();
//        System.out.println(innerClassSingleton1==innerClassSingleton);
        InnerClassSingleton instance = InnerClassSingleton.getInstance();
//        ObjectOutputStream testSerializable = new ObjectOutputStream(new FileOutputStream("testSerializable"));
//        testSerializable.writeObject(instance);
//        testSerializable.close();
        ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("testSerializable"));
        InnerClassSingleton o = ((InnerClassSingleton) inputStream.readObject());
        System.out.println(instance==o);
    }
}
